Skip to content

feat: add set_timeout / set_interval timer API (Phase 4 pull-forward)#11

Merged
niklabh merged 2 commits intomainfrom
timers
Mar 24, 2026
Merged

feat: add set_timeout / set_interval timer API (Phase 4 pull-forward)#11
niklabh merged 2 commits intomainfrom
timers

Conversation

@niklabh
Copy link
Copy Markdown
Owner

@niklabh niklabh commented Mar 24, 2026

Implement the timer scheduling system, pulled forward from Phase 4
because it is foundational for many guest app patterns.

Callback model:
- Guest calls set_timeout(callback_id, delay_ms) or
  set_interval(callback_id, interval_ms) to schedule timers
- Both return a timer ID for cancellation via clear_timer(id)
- The host fires expired timers by calling the guest-exported
  on_timer(callback_id) function each frame, before on_frame(dt_ms)
- One-shot timers are removed after firing; intervals reschedule
  automatically until cleared
- Timer resolution is tied to the frame rate (~16ms at 60fps)

Host (oxide-browser):
- Remove dead_code annotation from TimerEntry and timers field
- Add timer_next_id counter to HostState for unique timer IDs
- Add drain_expired_timers() utility that collects fired callbacks,
  removes one-shot timers, and reschedules intervals
- Register 3 host functions: api_set_timeout, api_set_interval,
  api_clear_timer
- Extend LiveModule to optionally capture on_timer export and
  fire expired timers in tick() before the on_frame call
- Timer callbacks get their own fuel budget to prevent runaway timers

SDK (oxide-sdk):
- Add set_timeout(), set_interval(), clear_timer() wrappers

Example (examples/timer-demo):
- Countdown timer using set_interval (ticks every 1s from 10 to 0)
- Delayed message using set_timeout (fires after 3 seconds)
- Blinking indicator using set_interval + clear_timer toggle
- Stopwatch using 100ms interval with start/stop/reset controls

niklabh added 2 commits March 24, 2026 21:50
Implement the timer scheduling system, pulled forward from Phase 4
because it is foundational for many guest app patterns.

Callback model:
- Guest calls set_timeout(callback_id, delay_ms) or
  set_interval(callback_id, interval_ms) to schedule timers
- Both return a timer ID for cancellation via clear_timer(id)
- The host fires expired timers by calling the guest-exported
  on_timer(callback_id) function each frame, before on_frame(dt_ms)
- One-shot timers are removed after firing; intervals reschedule
  automatically until cleared
- Timer resolution is tied to the frame rate (~16ms at 60fps)

Host (oxide-browser):
- Remove dead_code annotation from TimerEntry and timers field
- Add timer_next_id counter to HostState for unique timer IDs
- Add drain_expired_timers() utility that collects fired callbacks,
  removes one-shot timers, and reschedules intervals
- Register 3 host functions: api_set_timeout, api_set_interval,
  api_clear_timer
- Extend LiveModule to optionally capture on_timer export and
  fire expired timers in tick() before the on_frame call
- Timer callbacks get their own fuel budget to prevent runaway timers

SDK (oxide-sdk):
- Add set_timeout(), set_interval(), clear_timer() wrappers

Example (examples/timer-demo):
- Countdown timer using set_interval (ticks every 1s from 10 to 0)
- Delayed message using set_timeout (fires after 3 seconds)
- Blinking indicator using set_interval + clear_timer toggle
- Stopwatch using 100ms interval with start/stop/reset controls

Made-with: Cursor
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 24, 2026

Warning

Rate limit exceeded

@niklabh has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9f55806f-403c-4cc3-a755-175e5af6401c

📥 Commits

Reviewing files that changed from the base of the PR and between cbbdee7 and 75982fb.

📒 Files selected for processing (7)
  • Cargo.toml
  • ROADMAP.md
  • examples/timer-demo/Cargo.toml
  • examples/timer-demo/src/lib.rs
  • oxide-browser/src/capabilities.rs
  • oxide-browser/src/runtime.rs
  • oxide-sdk/src/lib.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch timers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@niklabh niklabh merged commit e42052a into main Mar 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant